package com.fafu.tool;

import com.fafu.domian.token.JsonRootBean;

import javax.swing.*;
import javax.xml.stream.FactoryConfigurationError;
import java.util.HashMap;
import java.util.Map;


public class TokenUtil {
	private static String api;
	private static String url;
	private static String token;
	public static String getToken(String name){
		url="http://139.224.192.113:8080/getToken?username=";
		api = url+name;
		String json = HttpClientUtil.doGet(api);
		JsonRootBean info = JsonUtils.parse(json,JsonRootBean.class);
		return token = info.getData().getToken();
	}
	public static Map checkToken(String token){
		url="http://139.224.192.113:8080/verifyToken?token=";
		api=url+token;
		Map map =new HashMap();
		String json =HttpClientUtil.doPost(api,token);
		JsonRootBean info =JsonUtils.parse(json,JsonRootBean.class);
		if(info.getCode() ==200){
			info.getData().getUsername();
			map.put("flag",true);
			map.put("username",info.getData().getUsername());
		}else {
			map.put("flag", false);
			map.put("username",null);
		}
		return map;
	}

}
